package no.uib.jexpress_modularized.core.dataset;

import java.io.Serializable;
import java.util.Random;

/**
 *
 * Class containing methods that generate random datasets.
 *
 * @author pawels
 */
public class DatasetGenerator implements Serializable{

    public static Random random = new Random();

    /**
     * Returns a randomly generated dataset of given size. Matric content has
     * values in range from -5.0 to 5.0. The missing values are randomly distributed,
     * and on average constitute 1/16 of the matrix.
     * @param length of data matrix (e.g. num of genes)
     * @param width of data matrix (e.g. num of samples)
     * @return a randomly generated dataset
     */
    public static Dataset generateDummyDataset(int length, int width) {

        double[][] m = new double[length][width];
        boolean[][] nulls = new boolean[length][width];

        for (int i = 0; i < length; i++) {
            for (int j = 0; j < width; j++) {
                m[i][j] = (random.nextDouble() * 10) - 5.0;
                nulls[i][j] = (random.nextBoolean()
                        && random.nextBoolean()
                        && random.nextBoolean()
                        && random.nextBoolean());
            }
        }
        Dataset dataset = Dataset.newDataSet(m, nulls);
        return dataset;
    }

    public static Dataset generateSmallRealDataset() {

        int length = 50;
        int width = 7;

        double[][] m = {
          { 0.20000000298023224,	0.03999999910593033,	0.1899999976158142,	0.4099999964237213,	0.7599999904632568,	2.180000066757202,	2.5 },
          { 0.0,                        -0.23000000417232513,	0.25,                   -0.8899999856948853,	-1.090000033378601,	-1.690000057220459,	-2.180000066757202 },
          { -0.49000000953674316,	-0.14000000059604645,	0.10000000149011612,	-0.3799999952316284,	-0.8399999737739563,	1.059999942779541,	2.2799999713897705 },
          { 0.03999999910593033,	-0.03999999910593033,	-0.11999999731779099,	-0.4300000071525574,	-0.49000000953674316,	-1.4700000286102295,	-2.119999885559082 },
          { 0.3199999928474426,         0.46000000834465027,	0.30000001192092896,	-0.20000000298023224,	-0.6700000166893005,	-1.7899999618530273,	-2.559999942779541 },
          { -0.44999998807907104,	0.11999999731779099,	0.6499999761581421,	0.9900000095367432,	0.800000011920929,	2.9800000190734863,	2.509999990463257 },
          { -0.11999999731779099,	0.11999999731779099,	0.2800000011920929,	-0.10000000149011612,	-0.4699999988079071,	1.659999966621399,	2.690000057220459 },
          { 0.20000000298023224,	0.10999999940395355,	0.05999999865889549,	-0.28999999165534973,	-0.27000001072883606,	-1.840000033378601,	-2.640000104904175 },
          { 0.23999999463558197,	0.07999999821186066,	0.23000000417232513,	-0.7099999785423279,	-0.6700000166893005,	-1.8899999856948853,	-2.319999933242798 },
          { 0.25,                       0.07999999821186066,	0.2800000011920929,	-0.8600000143051147,	-0.9200000166893005,	-1.559999942779541,	-2.740000009536743 },
          { 0.20000000298023224,	0.03999999910593033,	0.1899999976158142,	0.4099999964237213,	0.7599999904632568,	2.180000066757202,	2.5 },
          { 0.0,                        -0.23000000417232513,	0.25,                   -0.8899999856948853,	-1.090000033378601,	-1.690000057220459,	-2.180000066757202 },
          { -0.49000000953674316,	-0.14000000059604645,	0.10000000149011612,	-0.3799999952316284,	-0.8399999737739563,	1.059999942779541,	2.2799999713897705 },
          { 0.03999999910593033,	-0.03999999910593033,	-0.11999999731779099,	-0.4300000071525574,	-0.49000000953674316,	-1.4700000286102295,	-2.119999885559082 },
          { 0.3199999928474426,         0.46000000834465027,	0.30000001192092896,	-0.20000000298023224,	-0.6700000166893005,	-1.7899999618530273,	-2.559999942779541 },
          { -0.44999998807907104,	0.11999999731779099,	0.6499999761581421,	0.9900000095367432,	0.800000011920929,	2.9800000190734863,	2.509999990463257 },
          { -0.11999999731779099,	0.11999999731779099,	0.2800000011920929,	-0.10000000149011612,	-0.4699999988079071,	1.659999966621399,	2.690000057220459 },
          { 0.20000000298023224,	0.10999999940395355,	0.05999999865889549,	-0.28999999165534973,	-0.27000001072883606,	-1.840000033378601,	-2.640000104904175 },
          { 0.23999999463558197,	0.07999999821186066,	0.23000000417232513,	-0.7099999785423279,	-0.6700000166893005,	-1.8899999856948853,	-2.319999933242798 },
          { 0.25,                       0.07999999821186066,	0.2800000011920929,	-0.8600000143051147,	-0.9200000166893005,	-1.559999942779541,	-2.740000009536743 },
          { 0.20000000298023224,	0.03999999910593033,	0.1899999976158142,	0.4099999964237213,	0.7599999904632568,	2.180000066757202,	2.5 },
          { 0.0,                        -0.23000000417232513,	0.25,                   -0.8899999856948853,	-1.090000033378601,	-1.690000057220459,	-2.180000066757202 },
          { -0.49000000953674316,	-0.14000000059604645,	0.10000000149011612,	-0.3799999952316284,	-0.8399999737739563,	1.059999942779541,	2.2799999713897705 },
          { 0.03999999910593033,	-0.03999999910593033,	-0.11999999731779099,	-0.4300000071525574,	-0.49000000953674316,	-1.4700000286102295,	-2.119999885559082 },
          { 0.3199999928474426,         0.46000000834465027,	0.30000001192092896,	-0.20000000298023224,	-0.6700000166893005,	-1.7899999618530273,	-2.559999942779541 },
          { -0.44999998807907104,	0.11999999731779099,	0.6499999761581421,	0.9900000095367432,	0.800000011920929,	2.9800000190734863,	2.509999990463257 },
          { -0.11999999731779099,	0.11999999731779099,	0.2800000011920929,	-0.10000000149011612,	-0.4699999988079071,	1.659999966621399,	2.690000057220459 },
          { 0.20000000298023224,	0.10999999940395355,	0.05999999865889549,	-0.28999999165534973,	-0.27000001072883606,	-1.840000033378601,	-2.640000104904175 },
          { 0.23999999463558197,	0.07999999821186066,	0.23000000417232513,	-0.7099999785423279,	-0.6700000166893005,	-1.8899999856948853,	-2.319999933242798 },
          { 0.25,                       0.07999999821186066,	0.2800000011920929,	-0.8600000143051147,	-0.9200000166893005,	-1.559999942779541,	-2.740000009536743 },
          { 0.20000000298023224,	0.03999999910593033,	0.1899999976158142,	0.4099999964237213,	0.7599999904632568,	2.180000066757202,	2.5 },
          { 0.0,                        -0.23000000417232513,	0.25,                   -0.8899999856948853,	-1.090000033378601,	-1.690000057220459,	-2.180000066757202 },
          { -0.49000000953674316,	-0.14000000059604645,	0.10000000149011612,	-0.3799999952316284,	-0.8399999737739563,	1.059999942779541,	2.2799999713897705 },
          { 0.03999999910593033,	-0.03999999910593033,	-0.11999999731779099,	-0.4300000071525574,	-0.49000000953674316,	-1.4700000286102295,	-2.119999885559082 },
          { 0.3199999928474426,         0.46000000834465027,	0.30000001192092896,	-0.20000000298023224,	-0.6700000166893005,	-1.7899999618530273,	-2.559999942779541 },
          { -0.44999998807907104,	0.11999999731779099,	0.6499999761581421,	0.9900000095367432,	0.800000011920929,	2.9800000190734863,	2.509999990463257 },
          { -0.11999999731779099,	0.11999999731779099,	0.2800000011920929,	-0.10000000149011612,	-0.4699999988079071,	1.659999966621399,	2.690000057220459 },
          { 0.20000000298023224,	0.10999999940395355,	0.05999999865889549,	-0.28999999165534973,	-0.27000001072883606,	-1.840000033378601,	-2.640000104904175 },
          { 0.23999999463558197,	0.07999999821186066,	0.23000000417232513,	-0.7099999785423279,	-0.6700000166893005,	-1.8899999856948853,	-2.319999933242798 },
          { 0.25,                       0.07999999821186066,	0.2800000011920929,	-0.8600000143051147,	-0.9200000166893005,	-1.559999942779541,	-2.740000009536743 },
          { 0.20000000298023224,	0.03999999910593033,	0.1899999976158142,	0.4099999964237213,	0.7599999904632568,	2.180000066757202,	2.5 },
          { 0.0,                        -0.23000000417232513,	0.25,                   -0.8899999856948853,	-1.090000033378601,	-1.690000057220459,	-2.180000066757202 },
          { -0.49000000953674316,	-0.14000000059604645,	0.10000000149011612,	-0.3799999952316284,	-0.8399999737739563,	1.059999942779541,	2.2799999713897705 },
          { 0.03999999910593033,	-0.03999999910593033,	-0.11999999731779099,	-0.4300000071525574,	-0.49000000953674316,	-1.4700000286102295,	-2.119999885559082 },
          { 0.3199999928474426,         0.46000000834465027,	0.30000001192092896,	-0.20000000298023224,	-0.6700000166893005,	-1.7899999618530273,	-2.559999942779541 },
          { -0.44999998807907104,	0.11999999731779099,	0.6499999761581421,	0.9900000095367432,	0.800000011920929,	2.9800000190734863,	2.509999990463257 },
          { -0.11999999731779099,	0.11999999731779099,	0.2800000011920929,	-0.10000000149011612,	-0.4699999988079071,	1.659999966621399,	2.690000057220459 },
          { 0.20000000298023224,	0.10999999940395355,	0.05999999865889549,	-0.28999999165534973,	-0.27000001072883606,	-1.840000033378601,	-2.640000104904175 },
          { 0.23999999463558197,	0.07999999821186066,	0.23000000417232513,	-0.7099999785423279,	-0.6700000166893005,	-1.8899999856948853,	-2.319999933242798 },
          { 0.25,                       0.07999999821186066,	0.2800000011920929,	-0.8600000143051147,	-0.9200000166893005,	-1.559999942779541,	-2.740000009536743 }
        };

        boolean[][] nulls = new boolean[length][width];



        for (int i = 0; i < length; i++) {
            for (int j = 0; j < width; j++) {
                nulls[i][j] = (random.nextBoolean()
                        && random.nextBoolean()
                        && random.nextBoolean()
                        && random.nextBoolean());
            }
        }

        Dataset dataset = Dataset.newDataSet(m, nulls);
        return dataset;
    }


}
